const App = getApp();

Component({
  /**
   * 组件的对外属性，是属性名到属性设置的映射表
   */
  properties: {
    isShow: {
      type: Boolean
    },
    placeHolder: {
      type: String
    },
    dataLabel:{
      type: String
    },
    dataArr:{
      type: Array,
      value:[],
      observer(newVal) {
        
        this.setData({
          list:newVal
        },()=>{
          let time = setInterval(()=>{
            this.setData({
              searchList:this.data.searchList.concat(newVal.slice(this.data.startIndex+50,this.data.endIndex+50))
            })
          },300)
          if(newVal===this.data.searchList){
            clearInterval(time)
          }
        })
      
      }
    }
  },
  data: {
    list:[],
    value:'',
    searchList:[],
    startIndex:-50,
    endIndex:0
  },
  created () {
    console.log(this.data.list,111)
  },
  methods: {
    searchInput(e){
      this.setData({value:e.detail.value})
    },
    search(){
      this.setData({
        searchList:this.data.list.filter(e=>e.name.indexOf(this.data.value)>-1)
      })
      if(this.data.searchList.length===0){
        this.triggerEvent('hiddenCompany',false)
      }
    },
    cancelPre(){
      this.triggerEvent('hiddenCompany',false)
    },
    setSelectValue(e){
      this.triggerEvent('setSelectValue',{label:this.data.dataLabel,value:e.target.dataset.item})
      this.triggerEvent('hiddenCompany',false)
      this.setData({
        searchList:[],
        value:''
      })
    }
  }
})